package com.as.manager;

import java.util.List;

import com.as.entity.User;
import com.as.dao.UserDao;

public class UserManagerImpl implements UserManager{

    private UserDao userDao;
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}  

	@Override
	public User getUser(String userid) {
		return userDao.getById(userid);
	}

	@Override
	public boolean deleteUser(String id) {
		try{
			userDao.delete(id);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean updateUser(User user) {
		try{
			userDao.update(user);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public User login(String username, String password) {
		try{
		    return userDao.getUserByNameAndPwd(username, password);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean regist(User user) {
		try{
			userDao.save(user);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<User> getOneClassUser(int classNum) {
		return userDao.getOneClassUser(classNum);
	}

	@Override
	public User getUserbyname(String username) {
		try{
		    return userDao.getbyname(username);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public Object getUserbyemail(String email) {
		try{
		    return userDao.getbyemail(email);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
}
